package com.sykj.bsc.hyx.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sykj.bsc.hyx.bean.Bis_opinion;
import com.sykj.bsc.hyx.bean.Bis_sms_record;
import com.sykj.bsc.hyx.controller.miaodiyun.httpApiDemo.common.common.Accountlnfo;
import com.sykj.bsc.hyx.service.Bis_sms_recordService;

/*
 * 短信Controller
 * 胡颖箫
 * 2018/08/23
 */
/*
 * 短信显示和模糊查询，分页
 * 
 */
@Controller
@RequestMapping("Bis_sms_record")
public class Bis_sms_recordController {
	@Autowired
	public Bis_sms_recordService bis_sms_recordService;
	@RequestMapping("selectBis_sms_record")
	public String selectBis_sms_record(Model model,HttpServletRequest request,@RequestParam(value="page",defaultValue="1")int page){
		Map map=initMap(request);
		PageHelper.startPage(page, 5);
		List<Bis_sms_record> selectBis_sms_record=bis_sms_recordService.selectBis_sms_record(map);
		PageInfo<Bis_sms_record> pageInfo=new PageInfo<Bis_sms_record>(selectBis_sms_record);
		model.addAttribute("selectBis_sms_record", selectBis_sms_record);
		model.addAttribute("p", pageInfo);
		return "backstage/hyx/selectBis_sms_record";
	}
	private Map initMap(HttpServletRequest request) {
		//模糊查询；取和存值
				String mobile=request.getParameter("record_id");//收件人
				String content=request.getParameter("content");//短息内容
				String create_time1=request.getParameter("create_time1");//创建时间1
				String create_time2=request.getParameter("create_time2");//创建时间2
				String sms_type=request.getParameter("sms_type");//短息类型
				String status=request.getParameter("status");//状态
				String send_time1=request.getParameter("send_time1");//发起时间1
				String send_time2=request.getParameter("send_time2");//发起时间2
				Map<String, Object> map=new HashMap<>();
				map.put("mobile",mobile );//收件人
				map.put("content",content );//短息内容
				map.put("create_time1", create_time1);//创建时间1
				map.put("create_time2", create_time2);//创建时间2
				map.put("sms_type",sms_type );//短信类型
				map.put("status", status);//状态
				map.put("send_time1",send_time1 );//发起时间1
				map.put("send_time2", send_time2);//发起时间2
		        return map;
	}
	@RequestMapping("list")
	public String list(){
		return "backstage/hyx/saveRecord";
	}
	
	@RequestMapping("/saveRecord")
	public String insertlist(Bis_sms_record record,HttpServletRequest request){
		String mobile=request.getParameter("mobile");
		String content=request.getParameter("content");
		 try{
			// 获取开发者账号信息
			 Accountlnfo.execute();
			// 验证码通知短信接口   手机号和发送短信的内容
			 com.sykj.bsc.hyx.controller.miaodiyun.httpApiDemo.common.common.IndustrySMS.execute(mobile, content);
			 record.setStatus("1");
		 }catch(Exception e){
			 record.setStatus("0");
			 e.printStackTrace();
		 }
		this.bis_sms_recordService.saveRecord(record);
		return "redirect:/Bis_sms_record/selectBis_sms_record";
	}
	//全选删除和单选删除
	@RequestMapping("delete")
	public String delete(String ids){
		bis_sms_recordService.delete(ids);
		return "redirect:/Bis_sms_record/selectBis_sms_record";
	}
	
	
}
